package com.swallow.auth.infrastructure.impl.dept;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.swallow.auth.domain.dept.model.entity.DeptEntity;
import com.swallow.auth.domain.dept.repository.IDeptDomainRepository;
import com.swallow.auth.infrastructure.convert.dept.CvtDeptRepositoryMapper;
import com.swallow.auth.infrastructure.mysql.mapper.DepartmentMapper;
import com.swallow.auth.infrastructure.mysql.po.DepartmentPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-20 23:08:23
 * @version: v1.0
 * @describe: class responsibility
 */
@Service
public class DeptDomainRepositoryImpl implements IDeptDomainRepository {
    @Resource private DepartmentMapper departmentMapper;

    @Override
    public void create(DeptEntity deptEntity) {
        DepartmentPO departmentPO = CvtDeptRepositoryMapper.INSTANCE.deptEntity2PO(deptEntity);
        departmentMapper.insert(departmentPO);
    }

    @Override
    public Boolean nameRepeatCheck(DeptEntity deptEntity) {
        Long count = departmentMapper.selectCount(Wrappers.lambdaQuery(DepartmentPO.class)
                                                          .eq(DepartmentPO::getDeptName, deptEntity.getDeptName())
                                                 );
        return count >= 1;
    }


    @Override
    public List<DeptEntity> findSubDept(DeptEntity entity) {
        return null;
    }
}
